object ActivityAuditSystem extends App {
  // 定义学生类存储信息
  case class Student(
                      name: String,
                      major: String,          // 专业
                      programmingScore: Int,  // 编程成绩（-1表示无此成绩）
                      weeklyHours: Double,    // 每周可投入时间
                      hasDisciplineIssue: Boolean,  // 是否有违纪
                      isArtTalented: Boolean, // 是否有文艺特长
                      grade: Int,             // 年级（1=大一，2=大二，3=大三，4=大四）
                      peScore: Int,           // 体育成绩
                      meetsPhysicalReq: Boolean  // 是否达标体能要求
                    )

  // 审核函数：返回可参与活动及未通过原因
  def audit(student: Student): (List[String], Map[String, String]) = {
    var eligible = List.empty[String]
    var reasons = Map.empty[String, String]
    // 1. 编程大赛审核
    val isProgrammingEligible = {
      val majorOk = student.major.contains("计算机") || student.major.contains("软件")
      val scoreOk = student.programmingScore >= 85
      val timeOk = student.weeklyHours >= 10
      val disciplineOk = !student.hasDisciplineIssue
      (majorOk || scoreOk) && timeOk && disciplineOk
    }
    if (isProgrammingEligible) eligible = "编程大赛" :: eligible
    else {
      val reason = if (student.hasDisciplineIssue) "有违纪记录"
      else if (student.weeklyHours < 10) "每周时间不足10小时"
      else "非计算机相关专业且编程成绩<85"
      reasons += ("编程大赛" -> reason)
    }
    // 2. 文艺汇演审核
    val isArtEligible = {
      val talentOk = student.isArtTalented
      val rehearsalOk = student.grade <= 2 // 仅大一、大二
      talentOk && rehearsalOk
    }
    if (isArtEligible) eligible = "文艺汇演" :: eligible
    else {
      val reason = if (!student.isArtTalented) "无文艺特长"
      else "非大一或大二学生"
      reasons += ("文艺汇演" -> reason)
    }
    // 3. 田径运动会审核
    val isSportsEligible = student.peScore >= 80 && student.meetsPhysicalReq
    if (isSportsEligible) eligible = "田径运动会" :: eligible
    else {
      val reason = if (student.peScore < 80) "体育成绩<80"
      else "未达标体能要求"
      reasons += ("田径运动会" -> reason)
    }
    (eligible.reverse, reasons)
  }
  // 3. 测试数据（5种情况）
  val students = List(
    // 情况1：全通过（孙七）
    Student("孙七", "计算机科学", 90, 15, false, true, 2, 85, true),
    // 情况2：仅编程大赛通过
    Student("张三", "软件工程", 88, 12, false, false, 3, 75, false),
    // 情况3：仅文艺汇演通过
    Student("李四", "汉语言文学", -1, 8, false, true, 1, 70, false),
    // 情况4：仅田径运动会通过
    Student("王五", "机械工程", 70, 10, false, false, 2, 82, true),
    // 情况5：全不通过
    Student("赵六", "历史学", 60, 5, true, false, 4, 65, false)
  )
  // 4. 输出审核结果
  students.foreach { s =>
    val (eligible, reasons) = audit(s)
    println(s"=== ${s.name} 的审核结果 ===")
    println(s"可参与活动：${if (eligible.nonEmpty) eligible.mkString(", ") else "无"}")
    println("未通过原因：")
    reasons.foreach { case (activity, reason) =>
      println(s"  - $activity：$reason")
    }
    println()
  }
}